<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="include/peizhi.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="${ctx}">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
        
        <title>后台管理中心</title> 
		<link rel="stylesheet" href="${ctx}/css/pintuer.css" /> 
		<link rel="stylesheet" href="${ctx}/css/admin.css" /> 
        <script type="text/javascript" src="${ctx}/js/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="${ctx}/js/pagehoutai.js?v=20170530"></script>
    </head>
  	<body style="background-color:#f2f9fd;"> 
	  <jsp:include page="include/header.jsp" flush="true"/>
  <div class="admin"> 
	  <div class="panel admin-panel">
	    <div class="panel-head"><strong class="icon-reorder"> 友情链接</strong></div>
	    <div class="padding border-bottom">
	      <ul class="search">
	        <li>
	          <input type='checkbox' id='allSelect' /><button type="button"  class="button border-green" id="checkall"> 全选</button>
	          <button type="submit" class="button border-red" onclick='deleteyouqing()'><span class="icon-trash-o"></span> 批量删除</button>
	          <button type="button"  class="button border-green" id="add"> 添加友情链接</button>
	        </li>
	      </ul>
	    </div>
	    <form id='delete'>
		    <table id='pagehtml' class="table table-hover text-center">
		    </table>
	    </form>
	    <form id="pageForm" action="${ctx}/ht/youqing/getList">
			<input type="hidden" name="pageNo" id="pageNo" value="0" /> 
			<input type="hidden" name="pageSize" id="pageSize" value="10" /> 
			<input id='lastPage' type="hidden">
		</form>
	  </div>
	<script type="text/javascript">

	$("#checkall").click(function(){ 
	  $("input[name='id[]']").each(function(){
		  if (this.checked) {
			  this.checked = false;
		  }
		  else {
			  this.checked = true;
		  }
	  });
	});

	//分页
	page(1,$("#pageSize").val());
 	var listhead='<tr>'+
	      '<th width="120">公司名称</th>'+
	      '<th>公司名称(英)</th>'+
	      '<th>状态</th>'+
	    	'</tr>';
	    	 
	var listhtml = "<tr>";
	 	listhtml = listhtml + "<td><input type='checkbox' class='sequence' name='ids[{0}].id' value='{4}'/>{1}</td>";
	    listhtml = listhtml + "<td>{2}</td>";     
	    listhtml = listhtml + "<th><button type='button' id='button{5}' onclick='updateType({6},{7})'>{3}</button</th>";
	    /*	    listhtml = listhtml + "<td><div class='button-group'> "
 	    +"<a class='button border-main' href='${ctx}/ht/book/bookcontent?id={11}'><span class='icon-trash-o'></span> 展示</a>" */
	    /* +"<a class='button border-red' href='javascript:void(0)' onclick='return deletebook({8})'><span class='icon-trash-o'></span> 删除</a> </div></td>" */;
	 listhtml = listhtml + "</tr>";
	 function pageAppend(data){
	 	data.createdate = formatDate(data.createdate,'0');
		return listhtml.replace('{0}',data.id)
		.replace('{1}',data.name)
		.replace('{2}',data.ename) 
		.replace('{3}',data.type==0 ? "启用":"未启用")
		.replace('{4}',data.id)
		.replace('{5}',data.id)
		.replace('{6}',data.id)
		.replace('{7}',data.type);
	}
	function deleteyouqing(id){
		var ids;
		if(id!='' && id!=null){
			ids='youQingVo[0].ids='+id;
		}else{
			ids = $("#delete").serialize();
		}
		if(confirm("您确定要删除吗?")){
			$.ajax({
				url:"${ctx}/ht/youqing/delete",
				data:ids,
				type:"post",
				success:function(data){
					if(data=='0'){
						alert("删除成功");
						page($('#pageNo').val(),$("#pageSize").val());
					}else{
						alert("删除失败");
					}
				}
			});
			
		}
	}
	
	//判断单选框是否被选中
	//document.getElementById("checkboxID").checked
	$("#allSelect").click(function(){
		var fir = $(".sequence");
		if(document.getElementById("allSelect").checked){
			//选中
			for(var i=0;i<fir.length;i++){
			    fir[i].checked = true;
			}
		}else{
			for(var i=0;i<fir.length;i++){
			    fir[i].checked = false;
			}
		}
	});
	$("#add").click(function(){
		window.location.href = "/ht/youqing/addYouQingLianJie";
	});
	function updateType(id,type){
		$.ajax({
			url:"${ctx}/ht/youqing/updateType",
			data:{"id":id,"type":type},
			type:"post",
			success:function(data){
				if(data=='0'){
					if($("#button"+id).text()=="启用"){
						$("#button"+id).text("未启用");
					}else{
						$("#button"+id).text("启用");
					}
					//page($('#pageNo').val(),$("#pageSize").val());
				}else{
					alert("修改失败");
				}
			}
		});
	}
	</script>
  </div> 
 </body>
</html>